package com.newjiabo.web.controller.common;

import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.system.domain.SysRegion;
import com.newjiabo.system.service.ISysRegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 地址信息接口
 *
 * @author Chopper
 */
@RestController
@Api(tags = "公共;地址信息接口")
@RequestMapping("/common/region")
public class RegionController {

    @Resource
    private ISysRegionService regionService;

    @ApiOperation(value = "点地图获取地址信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityCode", value = "城市code", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "townName", value = "镇名称", dataType = "Long", paramType = "query")
    })
    @GetMapping(value = "/region")
    public AjaxResult getRegion(@RequestParam String cityCode, @RequestParam String townName) {
        return AjaxResult.success(regionService.getRegion(cityCode, townName));
    }

    @GetMapping(value = "/name")
    @ApiOperation(value = "根据名字获取地区地址id")
    public AjaxResult getItemByLastName(String lastName) {
        return AjaxResult.success(regionService.getItemByLastName(lastName));
    }

    @GetMapping(value = "/item/{id}")
    @ApiImplicitParam(name = "id", value = "地区ID", required = true, dataType = "Long", paramType = "path")
    @ApiOperation(value = "通过id获取子地区")
    public AjaxResult getItem(@PathVariable String id) {
        List<SysRegion> sysRegions = regionService.getItem(id);
        return AjaxResult.success(sysRegions);
    }

    @GetMapping(value = "/allCity")
    @ApiOperation(value = "获取所有的省-市")
    public AjaxResult getAllCity() {
        return AjaxResult.success(regionService.getAllCity());
    }

    @ApiOperation(value = "获取所有的省-市-区县")
    @GetMapping(value = "/AllCounty")
    public AjaxResult getAllCounty() {
        return AjaxResult.success(regionService.getAllCounty());
    }

}
